package com.system.borrow.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.system.borrow.MyApplication;
import com.system.borrow.R;
import com.system.borrow.bean.FastBean;

import java.util.ArrayList;
import java.util.List;

/**
 * ================================================
 * 作    者：LuCenly(落尘)
 * 版    本：1.0
 * 创建日期：2016/12/3 17:12
 * 描    述：TODO
 * ================================================
 */
public class FastListAdapter extends BaseAdapter{
    private List<FastBean> list = new ArrayList<>();
    private Context context;
    private LayoutInflater inflater;

    public FastListAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public List<FastBean> getList() {
        return list;
    }

    public void setList(List<FastBean> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView==null){
            convertView = inflater.inflate(R.layout.item_fast_list,null);
            viewHolder = new ViewHolder();
            viewHolder.iv_fast = (ImageView) convertView.findViewById(R.id.iv_fast);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        FastBean fastBean = list.get(position);
        MyApplication.imageLoader.displayImage(fastBean.img,viewHolder.iv_fast,MyApplication.long_options);
        return convertView;
    }

    public class ViewHolder{
        ImageView iv_fast;
    }
}
